package com.zhangxin.aiInterview.manager.work_flow.ai_hr_interviewer.api;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.zhangxin.aiInterview.manager.work_flow.ai_hr_interviewer.constants.CozeConstants;
import org.springframework.stereotype.Service;

import static com.zhangxin.aiInterview.manager.work_flow.ai_tec_interviewer.constants.CozeConstants.TOKEN;

/**
 * 创建用户本次智能体会话
 */
@Service
public class CreateHrConversation {

    private static final String URL = "https://api.coze.cn/v1/conversation/create";

    /**
     * 创建用户本次智能体会话
     * @return 会话id
     */
    public String create() {
        JSONObject body = new JSONObject();
        body.set("bot_id", CozeConstants.BOT_ID);

        HttpResponse response = HttpRequest.post(URL)
                .header("Authorization", TOKEN)
                .header("Content-Type", "application/json")
                .body(body.toString())
                .execute();
        System.out.println("创建用户会话：" + response.body());

        JSONObject result = JSONUtil.parseObj(response.body());
        return result.getJSONObject("data").getStr("id");
    }
}
